package cn.kgc.service.impl;

import cn.kgc.dto.MalfunctionDto;
import cn.kgc.dto.MalfunctionOptionsDto;
import cn.kgc.mapper.MalfunctionOptionsMapper;
import cn.kgc.pojo.Malfunction;
import cn.kgc.mapper.MalfunctionMapper;
import cn.kgc.service.MalfunctionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 故障 服务实现类
 * </p>
 *
 * @author psq
 * @since 2021-08-05
 */
@Service
public class MalfunctionServiceImpl extends ServiceImpl<MalfunctionMapper, Malfunction> implements MalfunctionService {

    private MalfunctionMapper malfunctionMapper;
    private MalfunctionOptionsMapper malfunctionOptionsMapper;

    public MalfunctionServiceImpl(MalfunctionMapper malfunctionMapper, MalfunctionOptionsMapper malfunctionOptionsMapper) {
        this.malfunctionMapper = malfunctionMapper;
        this.malfunctionOptionsMapper = malfunctionOptionsMapper;
    }


    @Override
    public List<MalfunctionDto> findSpecListByModelId(Long modelId) {
        // 根据商品id获取故障信息
        List<MalfunctionDto> list = malfunctionMapper.findSpecListByModelId(modelId);
        if (list != null) {
            for (MalfunctionDto malfunctionDto : list) {
                // 故障id
                Long malfId = malfunctionDto.getId();
                // 获取故障字典
                List<MalfunctionOptionsDto> malfunctionOptionsDtos = malfunctionOptionsMapper.getMfosByModelIdAndMalfIf(malfId);
                malfunctionDto.setOptionsList(malfunctionOptionsDtos);
            }
        }

        return list;
    }
}
